<template>
  <div>
    <h1>商品管理--添加商品</h1>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="商品名称">
        <el-input class="ipt" v-model="form.name" placeholder="请输入商品名称"></el-input>
      </el-form-item>
      <el-form-item label="商品描述">
        <el-input class="ipt" v-model="form.type" placeholder="请输入商品描述"></el-input>
      </el-form-item>
      <el-form-item label="所属分类">
        <el-select v-model="form.one" placeholder="请选择一级品类">
          <el-option label="区域一" value="shanghai"></el-option>
        </el-select>
        <el-select v-model="form.two" placeholder="请选择二级品类">
          <el-option label="区域一" value="shanghai"></el-option>
        </el-select>
      </el-form-item>
      <!-- 商品价格 -->
      <el-form-item label="商品价格">
        <el-input
        class="ipt1"
          :min="1"
          :max="9999"
          v-model="form.num"
          placeholder="价格"
          type="number"
        >
          <template slot="append">元</template>
        </el-input>
      </el-form-item>
      <!-- 商品库存 -->
      <el-form-item label="商品库存">
        <el-input
        class="ipt1"
          :min="1"
          :max="9999"
          v-model="form.num1"
          placeholder="库存"
          type="number"
        >
          <template slot="append">件</template>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-upload
          class="upload-demo"
          action="/api/product/upload.do"
          :file-list="form.fileList"
          list-type="picture"
          :on-success="handChange"
        >
          <img :src="this.list.imageHost + this.list.subImages" alt="" />
          <el-button size="small" type="primary">上传图片</el-button>
        </el-upload>
      </el-form-item>
      <el-form-item label="活动形式">
        <el-input type="textarea" v-model="form.desc"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { addComm,category } from "../../http/index";
export default {
  data() {
    return {
      list:[],
      form: {
        name: "",
        type: "",
        one: "",
        two: "",
        num: "",
        num1: "",
        desc: "",
        mainImage: "",
        subImages: "",
        fileList: [{}],
      },
      options: [{}],
      opt: [{}],
      val: "",
      value: "",
      editorOption: {},
    };
  },
  methods: {
    onSubmit() {
      addComm(this.form).then((res) => {
        console.log(res);
         alert("新增商品成功");
        // this.$router.push("/shopList");
      });
    },
    handChange(response, file, fileList) {
      console.log(response, file, fileList);
      this.list.subImages = response.data.uri;
    },
    //添加商品接口
    addList() {
      category().then((res) => {
        console.log(res);
        this.options = res.data.data;
      });
      category({ categoryId: this.value }).then((res) => {
        console.log(res);
        this.opt = res.data.data;
      });
    },
  },
  created() {
    this.addList();
  },
  mounted() {},
  components: {},
  computed: {},
  watch: {},
};
</script>

<style lang='scss' scoped>
.ipt {
  width: 50%;
}
.ipt1 {
  width: 20%;
}
</style>
